package cn.com.huzo.repository.tech.impl;

import cn.com.huzo.model.entities.tech.PieceYardageLinesEntity;
import cn.com.huzo.repository.tech.PieceYardageLinesRepository;
import huzofw.repository.impl.GenericRepositoryImpl;
import huzofw.repository.impl.MyBatisDaoUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Repository;

/**
 * 单耗数据访问对象。
 *
 * @author 吴旭
 */
@Repository("PieceYardageLinesRepository")
public class PieceYardageLinesRepositoryImpl extends GenericRepositoryImpl<PieceYardageLinesEntity, String>
        implements PieceYardageLinesRepository {

    private final String namespace = "cn.com.huzo.repository.tech.PieceYardageLinesRepository";

    /**
     * 构造函数,设置the instance to ProductRepositoryImpl.class.
     */
    public PieceYardageLinesRepositoryImpl() {
        super(PieceYardageLinesEntity.class);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public List<PieceYardageLinesEntity> fetchByHeaderKey(Long headerKey) {
        return getSqlSession().selectList(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchByHeaderKey"), headerKey);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer batchInsert(List<PieceYardageLinesEntity> itemList) {
        /*Map<String, Object> criterion = new HashMap();
        Long[] materiaIdlist = new Long[itemList.size()];
        for (int i = 0; i < itemList.size(); i++) {
            if (i == 0) {
                criterion.put("HeaderId", itemList.get(i).getHeaderId());
                criterion.put("CreatedBy", itemList.get(i).getCreatedBy());
                criterion.put("UpdatedBy", itemList.get(i).getUpdatedBy());
            }
            materiaIdlist[i] = itemList.get(i).getMaterialId();
        }
        criterion.put("list1", materiaIdlist);*/
        return getSqlSession().insert(MyBatisDaoUtils.getMapperQueryId(
                namespace, "insertLines"), itemList);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer batchUpdate(List<PieceYardageLinesEntity> itemsList) {
        return getSqlSession().update(MyBatisDaoUtils.getMapperQueryId(
                namespace, "updateLines"), itemsList);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer updateLinesByMaterialId(String linesId, Long materialId) {
        Map<String, Object> criterion = new HashMap();
        criterion.put("LinesId", linesId);
        criterion.put("MaterialId", materialId);

        return getSqlSession().update(MyBatisDaoUtils.getMapperQueryId(
                namespace, "updateLinesByMaterialId"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer delete(String key) {
        return getSqlSession().delete(MyBatisDaoUtils.getMapperQueryId(
                namespace, "delete"), key);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer batchDelete(List<PieceYardageLinesEntity> itemList) {
        return getSqlSession().delete(MyBatisDaoUtils.getMapperQueryId(
                namespace, "batchDelete"), itemList);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer batchClearLinesPieceYardage(List<PieceYardageLinesEntity> itemList) {
        return getSqlSession().delete(MyBatisDaoUtils.getMapperQueryId(
                namespace, "batchClearLinesPieceYardage"), itemList);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer updateLinesGrade(List<PieceYardageLinesEntity> itemsList) {
        return getSqlSession().update(MyBatisDaoUtils.getMapperQueryId(
                namespace, "updateLinesGrade"), itemsList);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer importLinesFromOtherBom(Long headerId, Long importedBomHeaderId, Long createdBy, Long updatedBy) {
        Map<String, Object> criterion = new HashMap();
        criterion.put("HeaderId", headerId);
        criterion.put("ImportedBomHeaderId", importedBomHeaderId);
        criterion.put("CreatedBy", createdBy);
        criterion.put("UpdatedBy", updatedBy);

        return getSqlSession().insert(MyBatisDaoUtils.getMapperQueryId(
                namespace, "importLinesFromOtherBom"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer insertFromClipboard(Long headerId, String copiedLinesId, Long materialId,
            Long uomId, String specification, Integer orderNo, Long createdBy, Long updatedBy) {
        Map<String, Object> criterion = new HashMap();
        criterion.put("HeaderId", headerId);
        criterion.put("CopiedLinesId", copiedLinesId);
        criterion.put("MaterialId", materialId);
        criterion.put("UomId", uomId);
        criterion.put("Specification", specification);
        criterion.put("OrderNo", orderNo);
        criterion.put("CreatedBy", createdBy);
        criterion.put("UpdatedBy", updatedBy);

        return getSqlSession().insert(MyBatisDaoUtils.getMapperQueryId(
                namespace, "insertFromClipboard"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer clearImportedBomLinesId(Long headerId) {
        return getSqlSession().update(MyBatisDaoUtils.getMapperQueryId(
                namespace, "clearImportedBomLinesId"), headerId);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer resetLinesOrder(Long headerKey) {
        return getSqlSession().update(MyBatisDaoUtils.getMapperQueryId(
                namespace, "resetLinesOrder"), headerKey);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer updateLinesOrder(List<PieceYardageLinesEntity> itemsList) {
        return getSqlSession().update(MyBatisDaoUtils.getMapperQueryId(
                namespace, "updateLinesOrder"), itemsList);
    }
}
